package com.kgc.scd.controller;

import com.kgc.scd.service.CollectService;
import com.kgc.scd.util.PageSupport;
import com.kgc.scd.vo.NideshopCollectVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collection;
import java.util.List;

/**
 * Created On : 2022/11/14.
 * <p>
 * Author : yantao
 * <p>
 * Description: CollectController
 */
@Slf4j
@RestController
@RequestMapping("/ytserver")
public class CollectController {
    @Autowired
    private CollectService collectService;

    /**
     * @author : yantao
     * @date   : 2022/11/15
     * @param  : [pageNo, pageSize, name, userId]
     * @return : com.kgc.scd.util.PageSupport<com.kgc.scd.vo.NideshopCollectVO>
     * @description : 查询所有收藏
     */
    @GetMapping("getCollectAll")
    public PageSupport<NideshopCollectVO> getCollectAll(@RequestParam Integer pageNo,
                                                        @RequestParam Integer pageSize,
                                                        @RequestParam String name,
                                                        @RequestParam String userId){

        log.info("++++++ server端接收信息:页数:{},{}",pageNo,pageSize);
        return collectService.selectCollectAll(pageNo,pageSize,name,userId);

    }

    /**
     * @author : yantao
     * @date   : 2022/11/15
     * @param  : [userId, goodsId]
     * @return : boolean
     * @description : 查看是否已经收藏商品
     */
    @GetMapping("testIsCollect")
    public boolean testIsCollect(@RequestParam String userId,
                                 @RequestParam String goodsId){

        log.info("++++++ testIsCollect端接收信息,查询收藏情况:消息:{},{}",userId,goodsId);


        return collectService.selectIsCollect(userId,goodsId);
    }

    /**
     * @author : yantao
     * @date   : 2022/11/18
     * @param  : [userId, goodsId]
     * @return : boolean
     * @description : 删除收藏
     */
    @GetMapping("/deleteCollection")
    public boolean deleteCollection(@RequestParam String userId,
                                    @RequestParam String goodsId){
        log.info("++++++ deleteCollection端接收信息,进行删除:消息:{},{}",userId,goodsId);
        return collectService.delectCollectByUserId(userId,goodsId);
    }


    /**
     * @author : yantao
     * @date   : 2022/11/18
     * @param  : [userId, goodsId]
     * @return : boolean
     * @description : 进行收藏
     */
    @GetMapping("/doCollect")
    public boolean doCollect(@RequestParam String userId,
                             @RequestParam String goodsId){
        log.info("++++++ doCollect端接收信息,进行收藏:消息:{},{}",userId,goodsId);

        return collectService.insertCollect(userId,goodsId);
    }






}
